<?php
    session_start();
    include('../../configs/connect.php');
    mysql_query("SET NAMES 'UTF8'");

$dsthi=$_GET['ma_ds'];
$sql_tt_dsthi=" SELECT  khungthoigian,ten_mh,ten_nganh,ngaythi,ten_donvi 
                FROM    tbl_dsthi,dm_cahoc,tbl_mon_ctdt,dm_monhoc,tbl_ctdt,dm_nganh,tbl_donvi,tbl_hoidongthi
                WHERE   tbl_dsthi.madm_ca=dm_cahoc.madm_ca
                AND     tbl_hoidongthi.ma_hoidong=tbl_dsthi.ma_hoidongthi
                AND     tbl_hoidongthi.ma_donvi=tbl_donvi.ma_donvi
                AND     tbl_dsthi.ma_mon_ctdt=tbl_mon_ctdt.ma_mon_ctdt
                AND     tbl_ctdt.ma_ctdt=tbl_mon_ctdt.ma_ctdt
                AND     tbl_mon_ctdt.ma_monhoc=dm_monhoc.madm_mh
                AND     tbl_ctdt.madm_nganh=dm_nganh.madm_nganh
                AND     ma_dsthi='$dsthi'";
                
$ex_tt_dslich=mysql_query($sql_tt_dsthi);
$kq=mysql_fetch_array($ex_tt_dslich);                

$sql_sv_lopmon="    SELECT  tbl_dangkymon.*,hoten_sv,ten_sv,ngaysinh_sv,ten_lop,ma_diemthi,lanthi,diemthi
                    FROM    tbl_dangkymon,tbl_sinhvien,tbl_nhaphoc,tbl_sv_lop,tbl_lop,tbl_diemthi
                    WHERE   tbl_dangkymon.ma_sv=tbl_sinhvien.ma_sv
                    AND     tbl_sinhvien.ma_sv=tbl_nhaphoc.ma_sv
                    AND     tbl_nhaphoc.ma_nhaphoc=tbl_sv_lop.ma_nhaphoc
                    AND     tbl_sv_lop.ma_lop=tbl_lop.ma_lop
                    AND     tbl_diemthi.ma_dkm=tbl_dangkymon.ma_dkm
                    AND     ngayra_nhaphoc = ''
                    AND     ma_dsthi='$dsthi'
                    ORDER BY ten_sv,hoten_sv ASC";
$ds_sv=null;
$ds_dkm=null;
$ex_sv_lopmon=mysql_query($sql_sv_lopmon);
while($row=mysql_fetch_array($ex_sv_lopmon)){
    $ds_sv[]=$row;
    $ds_dkm.="'".$row['ma_dkm']."',";
}

$ds_dkm=rtrim($ds_dkm,",");
                           
$ex_check_cc=mysql_query("  SELECT  tbl_ketquaquatrinh.ma_dkm,diem_kqqt 
                            FROM    tbl_dangkymon,tbl_ketquaquatrinh,tbl_monctdt_tieuchi
                            WHERE   tbl_dangkymon.ma_dkm=tbl_ketquaquatrinh.ma_dkm
                            AND     tbl_monctdt_tieuchi.ma_monctdt_tieuchi=tbl_ketquaquatrinh.ma_monctdt_tieuchi
                            AND     madm_tieuchimonhoc='cc'
                            AND     tbl_dangkymon.ma_dkm IN ($ds_dkm)");


$arr_kqqt_cc=array();
$arr_kqqt_cc=null;
$arr_kqqt_dk=array();
$arr_kqqt_dk=null;


if(mysql_num_rows($ex_check_cc)>0){
    while($row=mysql_fetch_array($ex_check_cc)){
        $key=$row['ma_dkm'];
        $arr_kqqt_cc[$key]=$row['diem_kqqt'];    
    }
    
        $ex_check_dk=mysql_query(" SELECT  tbl_ketquaquatrinh.ma_dkm,diem_kqqt 
                                    FROM    tbl_dangkymon,tbl_ketquaquatrinh,tbl_monctdt_tieuchi
                                    WHERE   tbl_dangkymon.ma_dkm=tbl_ketquaquatrinh.ma_dkm
                                    AND     tbl_monctdt_tieuchi.ma_monctdt_tieuchi=tbl_ketquaquatrinh.ma_monctdt_tieuchi
                                    AND     madm_tieuchimonhoc='dk'
                                    AND     tbl_dangkymon.ma_dkm IN ($ds_dkm)");
        
        if(mysql_num_rows($ex_check_dk)>0){
            while($row=mysql_fetch_array($ex_check_dk)){
                $key=$row['ma_dkm'];
                $arr_kqqt_dk[$key]=$row['diem_kqqt'];    
            }
        }
}
   
function ham_diemchu($diem){
    $diemchu=null;
    switch($diem){
        case '0': $diemchu="không"; break;
        case '1': $diemchu="một"; break;
        case '2': $diemchu="hai"; break;
        case '3': $diemchu="ba"; break;
        case '4': $diemchu="bốn"; break;
        case '5': $diemchu="năm"; break;
        case '6': $diemchu="sáu"; break;
        case '7': $diemchu="bảy"; break;
        case '8': $diemchu="tám"; break;
        case '9': $diemchu="chín"; break;
        case '10': $diemchu="mười"; break;
    }
    return $diemchu;
    
}   
   
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Bảng điểm</title>
<style type="text/css">
	*{
		margin:0;
		padding:0;
	}
	body{
		font-family:"Times New Roman", Times, serif;
		font-size:14px;
	}
	div{
		margin:10px 0px;
	}
    table {
        margin :0px 0px 0px 20px;
    }
	#container{
		width:210mm;
		margin:0px auto;
		padding:10px;
		
	}
	.left-header{
		float:left;
		width:40%;
		text-align:center;
	}
	.right-header{
		float:right;
		text-align:center;
		padding:0 40px 0 0;
	}
	.text-left{
		text-align:left;
		width:110px;
		border-right-style:none;
	}
	.c-left{
		float:left;
		width:55%;
		text-align:center;
	}
	.c-right{
		float:right;
		width:45%;
		text-align:center;
	}
	.left-footer{
		float:left;
		width:90mm;
		text-align:center;
	}
	.right-footer{
		float:right;
		width:110mm;
		text-align:center;
	}
	.bold{
		font-weight:bold;
	}
	.indent{
		text-indent:28px;
	}
	.width-120{
		width:130px;
	}
	p{
		text-align:justify;
	}
	td{
		padding:3px;
		border-bottom:1px dotted #000000;
		border-top:none;
		text-align:center;
	}
	th{
		padding-left:3px;
		border-bottom:1px solid #000000;
	}
	.bleft-none{
		text-align:left;
		border-left-style:none;	
	}
</style>
</head>

<body>
	<div id="container">
    	<div class="header">
        	<div class="left-header">
            	<span>VIỆN ĐẠI HỌC MỞ HÀ NỘI<br /><b style="font-size:18px">KHOA ĐÀO TẠO TỪ XA</b></span><hr />
            </div>
            <div class="right-header">
            </div>
        </div>
        <div style="clear:both"></div>
        <div style="text-align:center">
        	<span style="font-size:24px; font-weight:bold">BẢNG ĐIỂM TỔNG HỢP THI HẾT HỌC PHẦN</span><br />
            <span><b>Môn thi: <?php echo mb_strtoupper($kq['ten_mh'],'UTF-8')?></b></span>
        </div>
        <div>
        	<div class="c-left">
            	<span class="bold">
                    <p class="indent">Lớp: <br /></p>
                    <p class="indent">Ngành: <?php echo mb_strtoupper($kq['ten_nganh'],'UTF-8')?><br /></p>
                    <p class="indent">Địa điểm học: <?php echo mb_strtoupper($kq['ten_donvi'],'UTF-8')?><br /></p>
                </span>
            </div>
            <div class="c-right">
            	<span class="bold">
                   	<p>Năm nhập học: <br /></p>
                    <p>Ngày thi: <?php echo mb_strtoupper($kq['ngaythi'],'UTF-8')?><br /></p>
                    <p>Lần thi: 1<br /></p>
                </span>
            </div>
            <div>
                <table border="1px" cellpadding="0" cellspacing="0">
                	<tr>
                    	<th>STT</th>
                        <th class="text-left">HỌ VÀ </th>
                        <th class="bleft-none">TÊN</th>
                        <th>NGÀY SINH</th>
                        <th>ĐIỂM ĐK (30%)</th>
                        <th>ĐIỂM THI (70%)</th>
                        <th>ĐIỂM TỔNG</th>
                        <th>BẰNG CHỮ</th>
                        <th style="width:80px;">GHI CHÚ</th>
                    </tr>
            <?php   $i=1;
                    foreach($ds_sv as $key=>$value)
                    {
            ?>
                <tr>
                    <td><?php echo $i?></td>
                    <td class="text-left"><?php echo $value['hoten_sv']?></td>
                    <td class="bleft-none"><?php echo $value['ten_sv']?></td>
                    <td ><?php echo $value['ngaysinh_sv']?></td>
                    <td ><?php echo $arr_kqqt_cc[$value['ma_dkm']]?></td>
                    <td ><?php echo $arr_kqqt_dk[$value['ma_dkm']]?></td>
                    <td class="bold"><?php echo $value['diemthi']?></td>
                    <td><i><?php echo ham_diemchu($value['diemthi'])?></i></td>                                        
                    <td></td>
                </tr>
            <?php $i=$i+1;
                    } 
            ?>
                </table>
            </div>
            <div class="footer">
                <div class="left-footer">
                    <b>CÁN BỘ GIÁO VỤ</b>
                    <br /><br /><br /><br /><br /><br />
                    
                </div>
                <div class="right-footer">
                    TL. VIỆN TRƯỞNG<br />
                    <b>CN KHOA ĐÒA TẠO TỪ XA</b>
                    <br /><br /><br /><br /><br /><br />
                    <b>TS. Nguyễn Thanh Bình</b>
                </div>
            </div>
            <div style="clear:both"></div>
    </div>
</body>
</html>
